package com.ruoyi.system.controller.person;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Emplyee;
import com.ruoyi.system.service.IEmplyeeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 合同工Controller
 *
 * @author ruoyi
 * @date 2023-10-13
 */
@RestController
@RequestMapping("/emplyee")
public class EmplyeeController extends BaseController
{
    @Autowired
    private IEmplyeeService emplyeeService;

    /**
     * 查询合同工列表
     */
    @RequiresPermissions("person:emplyee:list")
    @GetMapping("/list")
    public TableDataInfo list(Emplyee emplyee)
    {
        startPage();
        List<Emplyee> list = emplyeeService.selectEmplyeeList(emplyee);
        return getDataTable(list);
    }
    /**
     * 查询所有合同工名称
     */
    @RequiresPermissions("person:emplyee:list")
    @GetMapping("/names")
    public List<String> getNames()
    {
        List<String> list = emplyeeService.selectEmplyeeNames();
        return list;
    }

    /**
     * 导出合同工列表
     */
    @RequiresPermissions("person:emplyee:export")
    @Log(title = "合同工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Emplyee emplyee)
    {
        List<Emplyee> list = emplyeeService.selectEmplyeeList(emplyee);
        ExcelUtil<Emplyee> util = new ExcelUtil<Emplyee>(Emplyee.class);
        util.exportExcel(response, list, "合同工数据");
    }

    /**
     * 获取合同工详细信息
     */
    @RequiresPermissions("person:emplyee:query")
    @GetMapping(value = "/{eno}")
    public AjaxResult getInfo(@PathVariable("eno") String eno)
    {
        return success(emplyeeService.selectEmplyeeByEno(eno));
    }

    /**
     * 新增合同工
     */
    @RequiresPermissions("person:emplyee:add")
    @Log(title = "合同工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Emplyee emplyee)
    {
        return toAjax(emplyeeService.insertEmplyee(emplyee));
    }

    /**
     * 修改合同工
     */
    @RequiresPermissions("person:emplyee:edit")
    @Log(title = "合同工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Emplyee emplyee)
    {
        return toAjax(emplyeeService.updateEmplyee(emplyee));
    }

    /**
     * 删除合同工
     */
    @RequiresPermissions("person:emplyee:remove")
    @Log(title = "合同工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{enos}")
    public AjaxResult remove(@PathVariable String[] enos)
    {
        return toAjax(emplyeeService.deleteEmplyeeByEnos(enos));
    }
}
